// 引入 net
// @ts-nocheck
import { net } from 'electron'
const baseUrl = process.env.VITE_DEV_SERVER_URL ? 'http://localhost:7004' : 'https://saddress.dizhi666.com'
export function httpReq(url:string, method:string, data:any) {
  return new Promise(resolve=>{
    let tempUrl = baseUrl+url
    
    const request = net.request({
      headers: {
        'Content-Type': 'application/json',
      },
      method: method || 'GET',
      url: tempUrl
    })
    request.write(JSON.stringify(data))
    request.on('response', response => {
      // console.log(`STATUS: ${response.statusCode}`)
      // console.log(`HEADERS: ${JSON.stringify(response.headers)}`)
      let result = ''
      response.on('data', (chunk) => {
        // console.log('data:',chunk.toString())
        result+=chunk.toString()
      })
      response.on('end', () => {
        resolve(JSON.parse(result))
        // console.log('end result:',result)
      })
    })
    request.end()
  })
  
}

